0

hey!
I`m a beginner in Java and I want to write a program that use try and catch method to send a msg if the average it calculate is not in [0-20]
I have already write this code but it always print 0! what is wrong with my code?!!!

using
System;

using
System.Collections.Generic;

using
System.Text;

 

namespace
Avarage

{

class Program

{

static void Main(string[] args)

{

string n, m;

float f,s=0;

int i, k;

Console.Write("Please enter the number of your lessons :");

n =
Console.ReadLine();

i =
Convert.ToInt32(n);

for (int j = 0; j < i; j++)

{

Console.Write("please enter lesson's mark 1 by 1 and press Enter key :");

m =
Console.ReadLine();

k =
Convert.ToInt32(m);

s=s+k;

f = s / i;

}

try

{

if (f < 0 || f > 20)

}

catch

{

Console.WriteLine("You entered an unexpected number");

}

}

}

}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by 3pid
0

You have code, but it is in C#.
Why don't you convert it to Java and then ask specific question of any issues you may face?

0

You have code, but it is in C#.
Why don't you convert it to Java and then ask specific question of any issues you may face?

yeah sorry!I meant c#!anyway my problem is solved!thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.