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");

}

}

}

}

Recommended Answers

All 2 Replies

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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.