Question: import java.util.*; class Tester { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println(Enter four variables under or equal to 255); System.out.println(First variable:); String
import java.util.*; class Tester { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter four variables under or equal to 255"); System.out.println("First variable:"); String a=sc.next(); System.out.println("Second variable:"); String b=sc.next(); System.out.println("Third variable:"); String c=sc.next(); System.out.println("Fourth variable:"); String d=sc.next(); int num[]={Integer.valueOf(a),Integer.valueOf(b),Integer.valueOf(c),Integer.valueOf(d)}; for(int x=0;x<3;x++){ System.out.println("Switch status for data value "+ num[x]+":"); for(int j=6;j<14;j++){ Integer.toBinaryString(num[x]); for(int y=8;y>0;y--){ if(num[x].substring(y-1,y)==1){ System.out.print("Switch sw5"+j+"is on"); }else{ System.out.print("Switch sw5"+j+"is off"); } } } } } }
I need help with my code for BPJ Java Project Masking Telemetry Data(without creating a new file/created scanner), I need to be able to imput four numbers and return "on" for 1 and "off" for 0 in their binary form. The line of code: "if(num[x].substring(y-1,y)==1){" is the main problem, as I can't think of other form of how to do it or if it's even legal.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
