Question
I finished a code and was wondering how do you make a printed statement saying the number of classes for student %d is not valid!
I finished a code and was wondering how do you make a printed statement saying "the number of classes for student %d is not valid!" and then make the code say "Enter classes and graduation year for student %d : the number of classes for student %d is not valid!" then go back to normal like "Enter classes and graduation year for student %d : "
here is the code
import java.util.Scanner;
public class Chpt8_Project {
public static void main(String[] args) {
int[][] arr = new int [10][2];
Scanner in = new Scanner(System.in);
for(int i = 0; i < 10; i++)
{
System.out.printf("Enter classes and graduation year for student %d : ", i+1);
arr[i][0] = in.nextInt();
arr[i][1] = in.nextInt();
while(arr[i][0] > 20 || arr[i][0] < 1)
{
System.out.printf("Enter valid courses left for graduation for student %d : ", i+1);
arr[i][0] = in.nextInt();
}
}
for(int i = 0; i < 10; i++)
{
System.out.printf("Student %d requires %d credits to graduate in year %d ", i+1, arr[i][0]*3, arr[i][1]);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started