Write a program that asks the user to enter three positive integer value; number, start, end and
Silicon Value, and then prints the Silicon table of the number from the starting number to the ending
number. After printing the table, our program should ask the user whether he or she wishes to perform
the operation again. If so, the loop should repeat; otherwise it should terminate.
Use a character input of y or Y to repeat, and n and N to terminate the loop. No break statement is
allowed.
NOTE: Perform input validation so that all numbers must be greater than 0 and the “start” number
should be less than “end” number.
NOTE: Silicon Number is multiplied with iteration counter as shown in the table below.
import java.util.Scanner;
import java.lang.*;
public class Main
{
public static void Silicontable(int number, int start, int end){
for(int i=start; i<=end;i++){
System.out.println(number+" * "+i+" = "+number*i);
}
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
boolean f=true;
while(f==true){
System.out.println("Enter three numbers: ");
int number, start, end;
number=in.nextInt();
start=in.nextInt();
end=in.nextInt();
Silicontable(number,start,end);
String c;
System.out.println("Do you want to perform another operation? y/n");
c=in.next();
if (c=="y" || c=="Y")
f=true;
else if(c=="n" || c=="N")
f=false;
}
}
}
Comments
Leave a comment